package cn.wolfcode.job;

import cn.wolfcode.wolf2w.cache.service.IStrategyStatisVORedisService;
import cn.wolfcode.wolf2w.cache.vo.StrategyStatisVO;
import cn.wolfcode.wolf2w.service.IPersonalService;
import cn.wolfcode.wolf2w.vo.PersonalVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/*
* redis数据持久化任务
*
* Cron表达式时一个字符串，字符串以5或6个空格隔开满分为6或7个域，每一个域代表一个含义Cron有如下两个语法格式；
*
* （1）Seconds Minutes Hours DayofMonth Month DayofWeek Year
*
* （2）Seconds Minutes Hours DayofMonth Month DayofWeek     spring
*
* */
@Component
public class RedisDataPersistenceJob {
    @Autowired
    private IStrategyStatisVORedisService strategyStatisVORedisService;
    @Autowired
    private IPersonalService personalService;
    //@Scheduled  定时任务标签
    //cron   任务计划表达式
    @Scheduled(cron = "0/20 * * * * ?" )
    public void doWork(){
        System.out.println("--------------------------");
        List<StrategyStatisVO> list= strategyStatisVORedisService.queryStrategyVoByPattern("*");
        for (StrategyStatisVO vo:list){
            strategyStatisVORedisService.updateStrategyVO(vo);
        }
    }

    @Scheduled(cron = "0/20 * * * * ?" )
    public void doWork2(){
        System.out.println("保存VO成功");
        List<PersonalVO> list = strategyStatisVORedisService.queryPersonalVOByPattern("*");
        if (list.size()!=0 && list!=null){
            for (PersonalVO vo:list){
                if (vo!=null){
                    strategyStatisVORedisService.updatePersonalVO(vo);
                }
            }
        }
    }

}
